<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家id - 预留字段（uuid）">
          <a-input placeholder="请输入专家id - 预留字段（uuid）" v-decorator="['expertId', validatorRules.expertId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家编号 - 唯一标识">
          <a-input placeholder="请输入专家编号 - 唯一标识" v-decorator="['experNum', validatorRules.experNum ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家姓名">
          <a-input placeholder="请输入专家姓名" v-decorator="['experName', validatorRules.experName ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家性别（字典数据，1：男；2：女）">
          <a-input placeholder="请输入专家性别（字典数据，1：男；2：女）" v-decorator="['experSex', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家年龄">
          <a-input placeholder="请输入专家年龄" v-decorator="['experAge', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家电话">
          <a-input placeholder="请输入专家电话" v-decorator="['experPone', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="医院">
          <a-input placeholder="请输入医院" v-decorator="['experHosp', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="坐诊时间">
          <a-input placeholder="请输入坐诊时间" v-decorator="['workTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="联系科室">
          <a-input placeholder="请输入联系科室" v-decorator="['contactDep', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="联系人">
          <a-input placeholder="请输入联系人" v-decorator="['contactPerson', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="联系电话">
          <a-input placeholder="请输入联系电话" v-decorator="['contactPhone', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="坐诊地点">
          <a-input placeholder="请输入坐诊地点" v-decorator="['workAddress', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家简介">
          <a-input placeholder="请输入专家简介" v-decorator="['experinTroduce', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家头像（保存头像名称，从项目指定文件夹中查找）">
          <a-input placeholder="请输入专家头像（保存头像名称，从项目指定文件夹中查找）" v-decorator="['experPhoto', {}]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "ExpertInforModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        expertId:{rules: [{ required: true, message: '请输入专家id - 预留字段（uuid）!' }]},
        experNum:{rules: [{ required: true, message: '请输入专家编号 - 唯一标识!' }]},
        experName:{rules: [{ required: true, message: '请输入专家姓名!' }]},
        },
        url: {
          add: "/hospital/expertInfor/add",
          edit: "/hospital/expertInfor/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'expertId','experNum','experName','experSex','experAge','experPone','experHosp','contactDep','contactPerson','contactPhone','workAddress','experinTroduce','experPhoto'))
		  //时间格式化
          this.form.setFieldsValue({workTime:this.model.workTime?moment(this.model.workTime):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>